package 创建型模式.建造者模式;

//	主要组成部分
//		产品 (Product): 最终要构建的复杂对象
//		抽象建造者 (Builder): 定义创建产品各个部分的抽象接口
//		具体建造者 (Concrete Builder): 实现Builder接口，构造和装配产品的各个部件
//		指挥者 (Director): 构建一个使用Builder接口的对象，控制构建过程



//套餐
class Meal
{
	private String burger;
	private String fries;
	private String drink;

	public String getBurger() {
		return burger;
	}

	public void setBurger(String burger) {
		this.burger = burger;
	}

	public String getFries() {
		return fries;
	}

	public void setFries(String fries) {
		this.fries = fries;
	}

	public String getDrink() {
		return drink;
	}

	public void setDrink(String drink) {
		this.drink = drink;
	}

	@Override
	public String toString() {
		return "Meal{" +
				"burger='" + burger + '\'' +
				", fries='" + fries + '\'' +
				", drink='" + drink + '\'' +
				'}';
	}
}

//@Data
abstract class BuilderMeal
{
	private Meal meal;
	
	
	abstract void BuiltBurger();
	abstract void BuiltFries();
	abstract void BuiltDrink();

	public Meal getMeal() {
		return meal;
	}

	public void setMeal(Meal meal) {
		this.meal = meal;
	}
}

class BuildA extends BuilderMeal
{
	@Override
	void BuiltBurger() {
		super.getMeal().setBurger("鸡肉汉堡包");
	}

	@Override
	void BuiltFries() {
		getMeal().setFries("大份薯条");
	}

	@Override
	void BuiltDrink() {
		getMeal().setDrink("火龙果汁");
	}
}

class BuildB extends BuilderMeal
{
	@Override
	void BuiltBurger() {
		getMeal().setBurger("牛肉汉堡包");
	}

	@Override
	void BuiltFries() {
		getMeal().setFries("小份薯条");
	}

	@Override
	void BuiltDrink() {
		getMeal().setDrink("可乐");
	}
}

abstract class BuilderMealChain
{
	private Meal meal;


	abstract BuilderMealChain BuiltBurger();
	abstract BuilderMealChain BuiltFries();
	abstract BuilderMealChain BuiltDrink();

	public Meal getMeal() {
		return meal;
	}

	public void setMeal(Meal meal) {
		this.meal = meal;
	}
}
//链式调用
class BuildC extends BuilderMealChain
{
	@Override
	BuilderMealChain BuiltBurger() {
		getMeal().setBurger("蔬菜汉堡包");
		return this;
	}
	

	@Override
	BuilderMealChain BuiltFries() {
		getMeal().setFries("中份薯条");
		return this;
	}

	@Override
	BuilderMealChain BuiltDrink() {
		getMeal().setDrink("雪碧");
		return this;
	}
}

public class BuilderPattern 
{
	public static void main(String[] args) {
		//A套餐
		BuilderMeal buildA = new BuildA();
		buildA.setMeal(new Meal());
		buildA.BuiltBurger();
		buildA.BuiltFries();
		buildA.BuiltDrink();
		System.out.println(buildA.getMeal());
		
		//B套餐
		BuilderMeal buildB = new BuildB();
		buildB.setMeal(new Meal());
		buildB.BuiltBurger();
		buildB.BuiltFries();
		buildB.BuiltDrink();
		System.out.println(buildB.getMeal());

		//C套餐
		//链式调用
		BuilderMealChain buildC = new BuildC();
		buildC.setMeal(new Meal());
		buildC.BuiltBurger().BuiltFries().BuiltDrink();
		System.out.println(buildC.getMeal());
	}
}
